
import { observable } from "mobx-miniprogram"

export default observable({
  isLogin:wx.getStorageSync("isLogin")||false,
  userInfo:wx.getStorageSync("userInfo")||{},
  token:wx.getStorageSync("token")||{},
  login(userInfo){
      console.log("登录")
      console.log("this.isLogin  ",this.isLogin);
      this.isLogin=true
      this.userInfo=userInfo
      this.token=userInfo.token||this.exitLogin()
      this.save()

      wx.navigateBack({
        delta: 1,
        complete:()=>{
          wx.showToast({
            title: '登录成功',
          })
        }
      })
      // wx.switchTab({
      //   url: '/pages/tabar/user/user',
      // })
      
  },
  save(){
    wx.setStorageSync("userInfo",this.userInfo)
    wx.setStorageSync("isLogin",this.isLogin)
    wx.setStorageSync("token",this.token)
  },
  exitLogin(){
    console.log("退出登录")
    this.isLogin=false
    this.userInfo={}
    this.token=""
    this.save()
    return ""
  }
})